package com.test.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.test.config.DynamicDataSource;
import com.test.entity.Order;
import com.test.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/orders")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping
    @DynamicDataSource("#tenantCode")
    public Page<Order> listOrders(
            @RequestParam String tenantCode,
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size) {
        return orderService.page(new Page<>(current, size));
    }

    @PostMapping
    @DynamicDataSource("#tenantCode")
    public Order createOrder(@RequestParam String tenantCode, @RequestBody Order order) {
        orderService.save(order);
        return order;
    }

    @GetMapping("/{id}")
    @DynamicDataSource("#tenantCode")
    public Order getOrder(@RequestParam String tenantCode, @PathVariable Long id) {
        return orderService.getById(id);
    }
} 